package com.javastudy.thread;

import com.javastudy.thread.model.StopThread;

public class StopThreadTest {

    public static void main(String[] args) throws InterruptedException {
        StopThread thread = new StopThread();
        thread.start();
        //休眠1秒，确保i自增成功
        Thread.sleep(1000);
        //暂停线程
//        thread.stop();//错误的执行，破坏了线程操作原子性
        thread.interrupt();//正确的执行
        while (thread.isAlive()){
            //确保线程已经终止
        }
        //输出结果
        System.out.println(thread.toString());
    }
}
